package ru.rchervot.sanasar.client.view;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public abstract class AbstractModuleHeaderSearchView extends
		AbstractModuleHeaderView implements AbstractModuleHeaderSearchPresenter.Display {
	
	private final DialogBox filters = new DialogBox();
	private final Button newCardButton = new Button("New card");
	
	public AbstractModuleHeaderSearchView(Widget searchBoxWidget) {
		super();
		
		leftPanel.add(newCardButton);
		leftPanel.setCellVerticalAlignment(newCardButton, HasVerticalAlignment.ALIGN_MIDDLE);
		basePanel.add(searchBoxWidget);
		basePanel.setCellHorizontalAlignment(searchBoxWidget,
				HasHorizontalAlignment.ALIGN_RIGHT);
		
		VerticalPanel t = new VerticalPanel();
//		t.add(queryWidget);
		t.setWidth("600px");
		
		filters.add(t);
		filters.hide();
		
	}

	@Override
	public HasClickHandlers getNewCardButton() {
		return newCardButton;
	}

	void showFiltersPanel() {
		filters.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
			public void setPosition(int offsetWidth,
					int offsetHeight) {
				int left = (Window.getClientWidth() - offsetWidth) / 2;
				int top = 0;
				filters.setPopupPosition(left, top);
			}
		});
	}
	
	void hideFiltersPanel() {
		filters.hide();
	}

}
